package com.yc.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.yc.bean.FoodBean;
import com.yc.mapper.FoodMapper;
import org.springframework.stereotype.Service;

/**
 * @author zwei
 * @create 2024-10-23 20:51
 */
@Service
public class FoodBizImpl implements FoodBiz{
    private FoodMapper foodMapper;
    public FoodBizImpl(FoodMapper foodMapper) {
        this.foodMapper = foodMapper;
    }
    @Override
    public void updateFood(int id, int count) {
        QueryWrapper<FoodBean> qw=new QueryWrapper<>();
        qw.eq("id",id);
        FoodBean foodBean = foodMapper.selectOne(qw);
        UpdateWrapper<FoodBean> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id", id).set("totalbuynum", foodBean.getTotalbuynum()+count);
        foodMapper.update(null, updateWrapper);
    }
}
